﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Util.Interface.System;
using Util.ServiceDAO.User;
using Util.SystemModel.System;

namespace Util.Service.System
{
    public class MenuService : IMenu
    {
        public List<MenuModel> GetFirstLevelMenu()
        {
            string where = " and Status=1 and Hierarchy=1 ";
            return MenuDAO.SelectMenuByWhere(where, null, " Order By Queue ASC");

        }

        public List<MenuContentModel> GetMenu(string parentId)
        {
            string where = " and Status=1  ";
            var list = MenuDAO.SelectMenuByWhere(where, null, " Order By Queue ASC");
            return GetMenus(parentId, list);
        }

        private List<MenuContentModel> GetMenus(string parentId, List<MenuModel> list)
        {
            List<MenuContentModel> menuList = new List<MenuContentModel>();
            var temp = list.Where(O => O.ParentId.Equals(parentId)).ToList();
            foreach (var item in temp)
            {
                menuList.Add(new MenuContentModel()
                {
                    children = GetMenus(item.MenuId, list),
                    href = item.Href,
                    icon = item.Icon,
                    spread = true,
                    title = item.Title
                });
            }
            return menuList;
        }
    }
}
